# qq format validation, works with qq format
class QqValidator < ActiveModel::EachValidator
  REGEXP = /^[1-9]*[1-9][0-9]*$/
  def validate_each(record, attribute, value)
    record.errors.add attribute, (options[:message] || I18n.t('rails_validation.qq.invalid')) unless value =~ REGEXP
  end
end
module ActiveModel
  module Validations
    module HelperMethods
      def validates_qq_of(*attr_names)
        validates_with QqValidator, _merge_attributes(attr_names)
      end
    end
  end
end
